import React from 'react';
import { connect } from 'umi';
import { Form, Modal, Row, Col, ConfigProvider } from 'antd';
import { QuickForm } from 'vv-frontend-components';
import { SearchInput } from '@/components/UserForm';
// import { getCandidateManager } from '@/services/components/userform';
import { getCandidateFilterName } from '@/services/myRecruit/candidate';
// 模糊查询
// const { Option } = Select;
const formItemLayout = {
    labelCol: { span: 6 },
    wrapperCol: { span: 14 }
};
// 筛选人下拉

// const renderFilterOption = filterList => {
//     return filterList.map(item => {
//         return <Option value={item.dictKey}>{item.dictName}</Option>;
//     });
// };

const addConfig = companyId => [
    {
        field: 'employeeId',
        label: '用人部门筛选官',
        key: 'employeeId',
        props: {
            ...formItemLayout
        },
        component: (
            // <Select placeholder="请输入筛选人姓名">
            //     {renderFilterOption(filterList)}
            // </Select>
            <SearchInput
                params={{
                    companyId,
                    roleName: '用人部门'
                }}
                requireParam={['companyId', 'roleName']}
                getData={params =>
                    getCandidateFilterName(params).then(res => {
                        if (res && res.code === 10000) {
                            return res.data || [];
                        }
                        return [];
                    })
                }
                selectProps={{
                    placeholder: '请输入筛选官姓名',
                    style: { minWidth: 200 },
                    allowClear: true
                }}
                fieldsName={{
                    value: 'id',
                    title: 'employeeName', // 展示字段
                    extraParams: 'employeeName', // 模糊查询字段
                    isBuLu: true
                }}
                // onChange={this.handleSelect}
            />
        ),
        config: {
            // initialValue: postDetail.postType ? postDetail.postType : [],
            rules: [{ required: true, message: '请输入筛选人姓名!' }]
        }
    }
];
const Filter = ({ Visible, params, onOk, onCancel, dispatch, form }) => {
    // const { candidateList, postApplyList } = common;
    const { candidateCode, companyId, fetchList, talentName, recruitName } = params;
    // 获取下拉项数据
    // useEffect(() => {
    //     if (candidateList === []) {
    //         // 用人部门筛选官
    //         dispatch({
    //             type: 'common/fetchFilterNameList',
    //             payload: {
    //                 code: 'postType'
    //             }
    //         });
    //     }
    // }, [candidateList, postApplyList]);

    // 提交筛选
    const handleOk = closeModel => {
        form.validateFields((err, values) => {
            if (!err) {
                dispatch({
                    type: 'common/addFilter',
                    payload: {
                        ...values,
                        employeeCode: values.employeeCode.split('-')[0],
                        candidateCode
                    },
                    success: () => {
                        fetchList({ pageNo: 1 });
                    }
                });
                // 关闭模态框
                closeModel();
                form.resetFields();
            }
        });
    };
    return (
        <Modal
            title="发起用人部门筛选"
            width="750px"
            visible={Visible}
            // confirmLoading={loading}
            onOk={() => {
                handleOk(onOk);
            }}
            onCancel={() => {
                onCancel();
                form.resetFields();
            }}
        >
            <ConfigProvider getPopupContainer={trigger => trigger.parentNode}>
                {/* <Spin spinning={loading}> */}
                <Form layout="horizontal">
                    <h3 style={{ marginLeft: '40px' }}>
                        {talentName}({recruitName})
                    </h3>
                    <QuickForm config={addConfig(companyId)} form={form} />
                    <Row>
                        <Col span={6}></Col>
                        <Col span={14}>注：选择筛选官并提交，系统将提交候选人简历信息给筛选官。</Col>
                    </Row>
                </Form>
                {/* </Spin> */}
            </ConfigProvider>
        </Modal>
    );
};

export default connect(({ common, loading }) => ({
    common,
    loading
}))(Form.create()(Filter));
